﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL.Entity;
using DAL.Persistencia;

namespace NewTierra.Pages.Servicos
{
    public partial class ListaSupplierPorServico : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BuscaServico();

                if (Request.QueryString["Tipo"].Equals("servico"))
                {
                    PopularGridSuppliersServico();
                }
                else
                {
                    PopularGridSuppliersSubServico();
                }
            }
        }

        #region Popular Dados

        protected void BuscaServico()
        {
            try
            {
                ServicoDAL sd = new ServicoDAL();

                lblTituloServico.Text = sd.ObterPorId(Convert.ToInt32(Session["IdServico"])).Servicos_Nome;
            }
            catch (Exception ex)
            {
                lblErroGridSuppliers.Text = ex.Message;
            }
        }

        protected void PopularGridSuppliersServico()
        {
            try
            {
                MontaServicoDAL msd = new MontaServicoDAL();

                GridListSuppliers.DataSource = msd.ListarTodosCondicaoPorServico(Convert.ToInt32(Session["IdServico"]));
                GridListSuppliers.DataBind();

            }
            catch (Exception ex)
            {
                lblErroGridSuppliers.Text = ex.Message;
            }
        }

        protected void PopularGridSuppliersSubServico()
        {
            try
            {
                MontaServicoDAL msd = new MontaServicoDAL();

                GridListSuppliers.DataSource = msd.ListarTodosCondicaoPorSubServico(Convert.ToInt32(Session["IdServico"]));
                GridListSuppliers.DataBind();

            }
            catch (Exception ex)
            {
                lblErroGridSuppliers.Text = ex.Message;
            }
        }

        #endregion

    }
}